package org.bigdata.framework.admin.web.util;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.UUID;

/**
 * 日期格式转换
 * 
 * @author Administrator
 * 
 */
public class DateUtils {

	public static Date getDate() {
		Date dateU = new Date();
		java.sql.Date date = new java.sql.Date(dateU.getTime());
		return date;
	}

	public static String getDate(String date, String format) {
		try {
			if (format == null)
				format = "yyyy-MM-dd HH:mm:ss";
			SimpleDateFormat sdf = new SimpleDateFormat(format);
			return sdf.format((Date) sdf.parse(date));
		} catch (Exception e) {
			return date;
		}

	}

	public static String getCutStr(String date) {
		return null;
	}

	public static String getDateTime() {
		SimpleDateFormat sdf;
		Date date = null;
		Calendar myDate = Calendar.getInstance();
		myDate.setTime(new Date());
		date = myDate.getTime();
		sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		return sdf.format(date);
	}

	public static String getDateNoStyle() {
		SimpleDateFormat sdf;
		Date date = null;
		Calendar myDate = Calendar.getInstance();
		myDate.setTime(new Date());
		date = myDate.getTime();
		sdf = new SimpleDateFormat("yyyyMMddHHmmss");
		return sdf.format(date);
	}

	public static String formatDate(Date date, String format) {
		if (format == null)
			format = "yyyy-MM-dd HH:mm:ss";
		SimpleDateFormat sdf = new SimpleDateFormat(format);
		return sdf.format(date);
	}
	
	public static String formatDate2(Date date,String format){
		String result="";
		SimpleDateFormat sdf=new SimpleDateFormat(format);
		if(date!=null){
			result=sdf.format(date);
		}
		return result;
	}
	
	
	public static Date formatString(String str,String format) throws Exception{
		SimpleDateFormat sdf=new SimpleDateFormat(format);
		return sdf.parse(str);
	}
	public static void main(String[] args) {
		 
		Calendar myDate = Calendar.getInstance();
		myDate.setTime(new Date());
		for (int i = myDate.get(Calendar.YEAR) + 1; i > 1990; i--) {
			System.out.println(i);

		}

	}

}
